package cn.lan.scau_hotel_service.service.impl;

import cn.lan.scau_hotel_service.entity.RoomType;
import cn.lan.scau_hotel_service.repository.RoomTypeRepository;
import cn.lan.scau_hotel_service.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class RoomTypeServiceImpl implements RoomTypeService {

    @Autowired
    RoomTypeRepository roomTypeRepository;

    @Override
    public RoomType getRoomTypeById(int id) {
        return roomTypeRepository.getRoomTypeById(id);
    }

    @Override
    public RoomType getRoomTypeByName(String roomTypeName) {
        return roomTypeRepository.getRoomTypeByTypeName(roomTypeName);
    }

    @Override
    public boolean saveRoomType(RoomType roomType) {
        return roomTypeRepository.save(roomType)!=null;
    }

    @Override
    @Transactional
    public boolean deleteRoomTypeById(int id) {
        return roomTypeRepository.deleteRoomTypeById(id)!=0;
    }

    @Override
    public List<RoomType> findAll() {
        return roomTypeRepository.findAll();
    }
}
